package org.chen.common.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
import org.springframework.context.annotation.Configuration;

import java.util.Collection;
import java.util.Calendar;

@Configuration
public class DailyStatsShardingAlgorithm implements PreciseShardingAlgorithm<java.util.Date> {

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<java.util.Date> shardingValue) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(shardingValue.getValue());
        int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        return "ds" + (dayOfMonth % 2);
    }
}
